﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sub.TaskPlanningDesk.Model.Objects;
using Sub.TaskPlanningDesk.Model.Repositories;
using Sub.TaskPlanningDesk.Model.Services.Account;

namespace Sub.TaskPlanningDesk.Model.Services.Projects
{
	public class ProjectService : IProjectService
	{
		private IProjectRepository _projectRepository;
		private IMembershipService _membershipService;
		public ProjectService(IProjectRepository projectRepository, IMembershipService membershipService)
		{
			_projectRepository = projectRepository;
			_membershipService = membershipService;
		}

		public Project[] GetUserProjects(string userName)
		{
			int? userID = _membershipService.GetUserId(userName);
			if (!userID.HasValue)
				throw new InvalidOperationException("User doesn't exist.");

			return _projectRepository.GetProjects(userID.Value);
		}

		public Project ByID(int projectID)
		{
			return _projectRepository.ByID(projectID);
		}
	}
}
